package com.lightjet.macross.base.upms.domain;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.lightjet.macross.common.core.BaseEntity;
import com.lightjet.macross.common.core.IntKeyBaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name="UPMS_RESOURCEINFO")
@Getter
@Setter
@NoArgsConstructor
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler","createDate","updateDate"})
@ApiModel(description = "资源信息实体类")
public class ResourceInfo extends IntKeyBaseEntity {

    public static enum ResourceTypeEnum  {
        MENU,//菜单
        BUTTON,//操作按钮
        WIDGET//首页部件
    }

    public ResourceInfo(Integer id)
    {
        this.id = id;
    }

/*    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "native")
    @GenericGenerator(name = "native", strategy = "native")
    @ApiModelProperty(value = "资源ID")
    private Integer id;*/

    //资源所属父节点
    @ManyToOne
    @JoinColumn(name="parentid")
    @JsonBackReference(value = "parent-child")
    @ApiModelProperty(value = "资源父节点")
    private ResourceInfo parent;

    @ApiModelProperty(value = "资源父节点ID")
    @Column(insertable = false,updatable = false)
    private Integer parentid;

    //资源所属系统
    @ManyToOne
    @JoinColumn(name="systemid")
    @JsonBackReference(value = "belongsystem")
    private SystemInfo belongsystem;

    //资源名称
    @ApiModelProperty(value = "资源名称")
    private String resourcename;

    //资源类型 0-菜单节点 | 1-菜单目录
    @ApiModelProperty(value = "资源类型 0-菜单节点 | 1-操作按钮 | 2-Widget")
    @Enumerated(EnumType.ORDINAL)
    private ResourceTypeEnum  resourcetype = ResourceTypeEnum .MENU;

    //资源地址
    @ApiModelProperty(value = "资源URI")
    private String uri;

    //资源显示图标
    @ApiModelProperty(value = "资源显示图标")
    private String icno;

    //其他参数1
    @ApiModelProperty(value = "资源其他参数1")
    private String argument1;

    //其他参数1
    @ApiModelProperty(value = "资源其他参数2")
    private String argument2;

    //是否启用 0-禁用 | 1-启用
    @ColumnDefault("1")
    @ApiModelProperty(value = "资源是否启用")
    private Integer enabled = 1;

    //排序值
    @ApiModelProperty(value = "资源排序值")
    private Integer orderno = 0;

    //备注
    @ApiModelProperty(value = "资源备注")
    private String remark;

    //是否隐藏 0-否 | 1-是
    @ColumnDefault("0")
    @ApiModelProperty(value = "是否隐藏 1 是 | 0 否")
    private Integer hide = 0;

    /** description:子集  */
    @OneToMany(fetch=FetchType.LAZY)
    @JoinColumn(name="parentid")
    @OrderBy("orderno")
    @JsonManagedReference(value = "parent-child")
    //@JsonIgnore
    private List<ResourceInfo> children = new ArrayList<>();
}
